package com.yc.ice.demo2.test;

import com.yc.ice.demo2.Message;
import com.yc.ice.demo2.OnlineBookPrx;
import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.ObjectPrx;
import com.zeroc.Ice.Util;
import org.apache.log4j.Logger;

/**
 * Created with IntelliJ IDEA.
 * description:
 * author: yc
 * date: 2020/12/2 21:20
 */
public class Client {

    private static Logger log = Logger.getLogger(Client.class.getSimpleName());

    public static void main(String[] args) {
        log.info("客户端启动...");
        int status = 0;
        // 通信器
        Communicator ic = null;
        try {
            // 初始化这个通信器
            ic = Util.initialize(args);
            // 根据地址生成一个服务代理对象
            // HelloIce -- 服务端那边自己定义的名字
            ObjectPrx proxy = ic.stringToProxy("OnlineBook:default -p 10000");
            // 转换成HelloService类型的代理服务
            OnlineBookPrx hello = OnlineBookPrx.checkedCast(proxy);
            //调用方法
            Message send = new Message("张三", 2, false, 13.2, "ersrorssssss");

            Message s = hello.bookTick(send);
            System.out.println(">>"+s.content);
        } catch (Exception e) {
            e.printStackTrace();
            status = 1;
        } finally {
            if (ic != null) {
                ic.destroy();
            }
        }
        System.exit(status);

    }

}
